package kr.co.happenstance.adapter;

import java.util.ArrayList;

import kr.co.happenstance.R;
import kr.co.happenstance.lib.vo.NoticeInfo;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class NoticeAdapter extends BaseAdapter {
	protected final String TAG = "<<<NoticeAdapter>>>";
	
	private LayoutInflater inflater = null;
	private ArrayList<NoticeInfo> noticeList;
	private ViewHolder viewHolder = null;
	
	public NoticeAdapter(Context context, ArrayList<NoticeInfo> _list){
		this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.noticeList = _list;
	}	
	
	@Override
	public int getCount() {
		return noticeList.size();
	}

	@Override
	public Object getItem(int position) {
		return noticeList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		try{
			if(v == null){
				 v = inflater.inflate(R.layout.adapter_notice, parent, false);
				 viewHolder = new ViewHolder();
				 viewHolder.tvTitle = (TextView) v.findViewById(R.id.tv_title);
				 v.setTag(viewHolder);
			}else{
				viewHolder = (ViewHolder)v.getTag();
			}
			
			viewHolder.tvTitle.setTag(Integer.toString(position));
			viewHolder.tvTitle.setText(noticeList.get(position).title);
			
		}catch(Exception e){
			e.printStackTrace();
		}
		return v;
	}
	
	private class ViewHolder{
		public TextView tvTitle = null;
	}	
	
}
